﻿package client;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import server.ComBuyInterface;
import client.Configuration;

import javax.swing.JButton;

public class ComHouseInforGUI extends JDialog {

	private JPanel contentPane;
	private JTable table;

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ComHouseInforGUI frame = new ComHouseInforGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ComHouseInforGUI() {
		setTitle("房子状况");
		setModalityType(ModalityType.APPLICATION_MODAL);
		setBounds(100, 100, 603, 378);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnNewButton = new JButton("\u8FD4\u56DE");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				ComLoadGUI clg = new ComLoadGUI();
				clg.setLocationRelativeTo(null);
				clg.setVisible(true);
				
			}
		});
		btnNewButton.setBounds(467, 289, 93, 23);
		contentPane.add(btnNewButton);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(30, 10, 307, 191);
		contentPane.add(scrollPane);
		
		
		Configuration config=new Configuration();
		String rmiAddress=config.getRmiAddress();
		
		try {
			ComBuyInterface comBuy = (ComBuyInterface) Naming.lookup(rmiAddress+"ComBuyList");
			
			String[] b = {"high","middle","low"};
			String[] c = {"高级","中级","低级"};
			
			Object [][] a = new Object [3][];
			for(int i = 1;i <= 3; i++){
				int ha = comBuy.getHap(b[i-1]);
				double m = comBuy.getMon(b[i-1]);
				a[i-1] = new Object[3];
				a[i-1][0] = new String(c[i-1]);
				a[i-1][1] = new Integer(ha);
				a[i-1][2] = new Double(m);
			}
			
			table = new JTable();
			table.setModel(new DefaultTableModel(
				a,
				new String[] {
					"\u623F\u5B50\u7C7B\u578B", "Hap", "Money"
				}
			));
			scrollPane.setViewportView(table);
			
			JButton button = new JButton("\u9AD8\u7EA7\u623F\uFF08\u4E09\u5BA4\u4E24\u5385\uFF09");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dispose();
					ComHighGUI chg = new ComHighGUI();
					chg.setLocationRelativeTo(null);
					chg.setVisible(true);
					
				}
			});
			button.setBounds(347, 24, 194, 33);
			contentPane.add(button);
			
			JButton button_1 = new JButton("\u4E2D\u7EA7\u7EA7\u623F\uFF08\u4E09\u5BA4\u4E00\u5385\uFF09");
			button_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dispose();
					ComMiddleGUI cmg = new ComMiddleGUI();
					cmg.setLocationRelativeTo(null);
					cmg.setVisible(true);
					
				}
			});
			button_1.setBounds(347, 84, 194, 33);
			contentPane.add(button_1);
			
			JButton button_2 = new JButton("\u4F4E\u7EA7\u623F\uFF08\u4E24\u5BA4\u4E00\u5385\uFF09");
			button_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dispose();
					ComLowGUI clg = new ComLowGUI();
					clg.setLocationRelativeTo(null);
					clg.setVisible(true);
					
				}
			});
			button_2.setBounds(347, 147, 194, 33);
			contentPane.add(button_2);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
	}
}
